#include "stm32f10x.h"
#include "Delay.h"
#include "OLED.h"
#include "Zigbee.h"
#include "DHT11.h"
#include "MQ135.h"
#include "Buzzer.h"

int main(){
	Delay_Init();
	Zigbee_Init();
	OLED_Init();
	DHT11_Init();
	MQ4_Init();
	Buzzer_Init();
	OLED_Clean_Screen();
	
	//Zigbee_Send((uint8_t*)"AT+ZIGB_UIDTOID=A000\r\n");
	while(1){
		//OLED_Set_LinkState(Zigbee_LinkState());
		
		
		DHT11_ReadData();
		MQ4_ReadData();
		MH_ReadData();
		
		OLED_Set_Temp(dht11_data.temp_int, dht11_data.temp_fra);
		OLED_Set_Hump(dht11_data.humi_int, dht11_data.humi_fra);
		OLED_Set_Smok((uint8_t)mq4_data/10, mq4_data%10);
		OLED_Set_Fire((uint8_t)mh_data/10, mh_data%10);
		
		uint8_t data[12] = {0xff};
		data[1] = dht11_data.temp_int | (1<<7);
		data[2] = dht11_data.temp_fra | (1<<7);
		data[3] = dht11_data.humi_int | (1<<7);
		data[4] = dht11_data.humi_fra | (1<<7);
		data[5] = (uint8_t)mq4_data/10| (1<<7);
		data[6] = mq4_data%10					| (1<<7);
		data[7] = (uint8_t)mh_data/10 | (1<<7);
		data[8] = mh_data%10					|	(1<<7);
		data[9] = '\r';
		data[10] = '\n';
		
		Zigbee_Send((uint8_t*)"AT+ZIGB_UIDTOID=A000\r\n");
		Delay_Ms(1000);
		Zigbee_Send((uint8_t*)"AT+UT_SEND=03,A000,");
		Zigbee_Send((uint8_t*)data);

		Delay_Ms(1000);
	}
}
